<?php

include_once FILE_CLASS_SJABLOON;
include_once FILE_CLASS_TEXTOBJECT;

$recht_bitfield = new RechtBitfield();
$recht_bitfield->setBitfield($data_array_bitfield);
if ($recht_bitfield->heeftRecht('16') == false) {

 echo '<script type="text/javascript">      
           alert(\'Geen Rechten!\');
           window.location = "index.php";
           </script>';
            exit;
}else{

$versie_nr = '';
$sjabloon_class = new Sjabloon();

if(isset($_GET['versie_nr'])){
    if(is_numeric($_GET['versie_nr'])){
     $versie_nr = $_GET['versie_nr']; 
     $sjabloon = $sjabloon_class->getSjabloon($versie_nr);
    }    
}else{
   echo 'Ongeldig versienummer!';
}

////$rechten_array = array(RIGHT_ADMIN_ADD, RIGHT_ADMIN_DEL_USER);
//
//$recht = new RechtBitfield();
//$recht->addRecht($rechten_array);
//                    $rechten_toevoegen = array(RIGHT_ADMIN_ADD, RIGHT_ADMIN_DEL_USER);
//                
//                    if($recht->heeftRechten($rechten_toevoegen)){
//                } else { 
//                    echo 'error';
//                }

?>
<link rel="stylesheet" href="../css/stylesheet.css" type="text/css" />
<div id="header">
    <div id="logo"></div>
    <div id="headertext">Sjablonen VGP</div>
</div>
<div id="content2">
    <div id="contentbg">
        <div id="contentblock1">
            <div id="contentblock1text">
                <table border="1" width="590px" style="background-color:#FFFFFF; border-color: #C6C6C6 ;">
                    <?php
                    echo '<th style="background-color: #D0CF22; color: #000000; font-size:16px;">' . VGP_SJABLOON_TEKST_RG . '</th><th style="background-color: #D0CF22; color: #000000; font-size:16px;">' . VGP_SJABLOON_TEKST_RISICO . '</th><th style="background-color: #D0CF22; color: #000000; font-size:16px;">' . VGP_SJABLOON_TEKST_PM . '</th>';
                    //Sjabloon array

                    foreach( $sjabloon as $idx => $ragv_array ){
                        if(!is_array($ragv_array)){
                                    continue;
                                }
                        //Risicoaandachtsgebied versie array
                        foreach($ragv_array as $idx2 => $rag_array){
                            //Skip risicoaandachtsgebied versie
                            if ( strcmp( $idx2 , 'risicoaandachtsgebied_versie') == 0 ) continue;
                            if(!is_array($rag_array)){
                                    continue;
                                }
                            
                            //risicoaandachtsgebied array
                            foreach( $rag_array as $idx3 => $rag_array_output ){
                                if (array_key_exists('risico_aandachtsgebied_naam',$rag_array_output )){
                                    echo '<tr style="background-color: #EDE9E4; color: #000000; font-size:16px ;"><td colspan="3">Risico&#39s van ' . $rag_array_output['risico_aandachtsgebied_naam'] . '</td></tr>';
                                    continue;
                                }
                                
                                if(!is_array($rag_array_output)){
                                    
                                    continue;
                                }

                                //risicogebied versie array
                                foreach( $rag_array_output as $idx4 => $rgv_array){

                                    // Skip risicogebied versie
                                    if ( strcmp( $idx4 , 'risicogebied_versie') == 0 ) continue;                                    
                                        if(!is_array($rgv_array)){
                                            continue;
                                        }
                                    //risicogebied array                                  
                                    foreach( $rgv_array as $idx5 => $rg_array ){
                                        if (array_key_exists('risico_gebied_naam',$rg_array )){
                                            echo '<tr style="background-color: #FFFFFF; color: #000000; font-size:14px"><td>' . $rg_array['risico_gebied_naam'] . '</td>';
                                            $risico_index = 0;
                                            continue;
                                        }
                                        
                                        if(!is_array($rg_array)){
                                                        continue;
                                                    }
                                        
                                       echo '';              //*/
                                      foreach( $rg_array as $idx5b => $rg_array_output){
                                          if ( strcmp( $idx5b , 'risico_versie') == 0 ) continue;
                                          if ( strcmp( $idx5b , '$rg_array_output') == 0 ) continue;
                                          
                                          if(!is_array($rg_array_output)){
                                               continue;
                                          }
                                            
                                       //risico versie array
                                        foreach( $rg_array_output as $idx6 => $rv_array){
                                            

                                            
                                          //Skip risico versie
                                        if (array_key_exists('risico_naam',$rv_array )){
                                            if ($risico_index != '0'){
                                             echo '</tr><tr class="risico_row_index"><td>&nbsp;</td>';
                                        }
                                            echo '<td style="background-color: #FFFFFF; color: #000000; font-size:14px">' . $rv_array['risico_naam'] . '</td>';
                                            $maatregel_index = 0;
                                            continue;
                                        }
                                        
                                          if ( strcmp( $idx6 , 'risico_versie') == 0 ) continue;
                                            if(!is_array($rv_array)){
                                                 continue;
                                             }
                                             
                                            //risico array
                                            foreach( $rv_array as $idx7 => $r_array){
                                                if(!is_array($r_array)){
                                                 continue;
                                                }
                                                //maatregel versie array
                                                $lvl8_cnt = 0;
                                                foreach( $r_array as $idx8 => $r_array_output){
                                                    
                                                    if ( strcmp( $idx8 , 'preventieve_maatregel_versie') == 0 ) continue;
                                                    if(!is_array($r_array_output)){
                                                        continue;                                                        
                                                    }
                                                    
                                                    if ($maatregel_index != '0') {
                                                                echo '</tr><tr class="pm_row_index"><td>&nbsp;</td><td>&nbsp;</td>';
                                                    }
                                                    
//                                                    if(!empty($r_array_output['preventieve_maatregel_naam'])){
                                                        echo '<td style="background-color: #FFFFFF; color: #000000; font-size:14px">' . $r_array_output['preventieve_maatregel_naam'] . '</td></tr>';
                                                    //}
                                                        $maatregel_index++;
                                                }
                                                
                                            
                                                  
                                                }
                                                $risico_index++;
                                            }
                                        }
//                                      if(!isset($rg_array_output)){
//                                          echo '<td></td>';
//                                      }                                        
                                    }
                                }
                                
 
                        }
                    } 
                   // var_dump($rag_array);
                  }
                    ?>
                    
                </table>
                <p>
                    <a style="float: left;" id="koppelknoppen" href="index.php?page=overzicht_sjabloonlijst">
                        Terug
                    </a>    
                </p>
            </div>
        </div>
    </div>        
</div>
<?php
}
?>